<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>复选框</title>
<script>
  function inverse() {
    var arr = document.getElementsByName("cb");
    for (var i = 0; i < arr.length; i++) {
      // 反选
      arr[i].checked = arr[i].checked !== true;
    }
  }
  function slt() {
    var str = "";
    var arr = document.getElementsByName("cb");
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].checked === true) {
        // 如果arr[i]不是第一个已勾选的checkbox
        if (str !== "") {
          // 使用“、”将之前的checkbox与arr[i]隔开
          str = str + "、";
        }
        str = str + arr[i].value;
      }
    }
    alert("你选择的项为" + str);
  }
</script>
</head>
<body>
  选择项
  <label><input type="checkbox" name="cb" value="value1">1</label>
  <label><input type="checkbox" name="cb" value="value2">2</label>
  <label><input type="checkbox" name="cb" value="value3">3</label>
  <label><input type="checkbox" name="cb" value="value4">4</label>
  <label><input type="checkbox" name="cb" value="value5">5</label>
  <input type="button" value="反选" onclick="inverse()">
  <button onclick="slt()">确定</button>
</body>
</html>